package com.itheima.service.impl;

import com.itheima.mapper.WaterQualityMapper;
import com.itheima.service.WaterQualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WaterQualityServiceImpl implements WaterQualityService {

    @Autowired
    private WaterQualityMapper waterQualityMapper;

    @Override
    public List<Map<String, Object>> getRealtimeData(String tableName) {
        String column;
        switch (tableName) {
            case "1_water_temperature":
                column = "temperature";
                break;
            case "2_dissolved_oxygen":
                column = "dissolved_oxygen";
                break;
            case "3_ph_value":
                column = "ph";
                break;
            default:
                throw new IllegalArgumentException("不支持的表名: " + tableName);
        }
        return waterQualityMapper.fetchRealtimeData(tableName, column);
    }


    @Override
    public List<Map<String, Object>> getHistoryData(String tableName) {
        String column;
        switch (tableName) {
            case "1_water_temperature":
                column = "temperature";
                break;
            case "2_dissolved_oxygen":
                column = "dissolved_oxygen";
                break;
            case "3_ph_value":
                column = "ph";
                break;
            default:
                throw new IllegalArgumentException("不支持的表名: " + tableName);
        }
        return waterQualityMapper.fetchHistoryData(tableName, column);
    }
}

